package com.tulele.vtool.handler;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.oracle.jrockit.jfr.ValueDefinition;
import com.tulele.vtool.model.ArticleTypeInfo;
import com.tulele.vtool.model.MateriaUserRelateTypeInfo;
import com.tulele.vtool.model.UserRelateArticleTypeInfo;
import com.tulele.vtool.model.combinedEntity.CombinedUserArticleTypeInfo;
import com.tulele.vtool.model.combinedEntity.UserBrandCombinedInfo;
import com.tulele.vtool.model.logEntity.PageDetailLog;
import com.tulele.vtool.model.reqEntity.RecordBrandReqBean;
import com.tulele.vtool.model.reqEntity.RecordUserArticleTypeInfoReqBean;
import com.tulele.vtool.model.respEntity.RespData;
import com.tulele.vtool.model.respEntity.ReturnCode;
import com.tulele.vtool.service.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.stream.Collectors;

@RestController
public class UserArticleTypeHandler {

    @Autowired
    private IUserRelateArticleTypeInfoService userRelateArticleTypeInfoService;

    @Autowired
    private IUserBrandInfoService userBrandInfoService;

    @Autowired
    private IArticleBrandAndTypeInfoService articleBrandAndTypeInfoService;

    @Autowired
    private IArticleTypeInfoService articleTypeInfoService;

//    @Value("${spring.profiles.active}")
//    private String springProfilesActive;

    @Autowired
    private ConnectionInfoService connectionInfoService;

    @Autowired
    private HeadlineService headlineService;

    /**
      * @Author: chujiu
      * @Description: 文章视频获取头部
      * @Date: 10:50 2020/7/24
      * @Param:
      * @param userId
      * @Return: articleTypeInfo、brandInfo
      **/
    @PostMapping(value = "/getUserSubBrandAndTypeInfo", produces="application/json;charset=UTF-8")
    public RespData getUserSubBrandAndTypeInfo(@RequestHeader("userId") String userId, @RequestHeader("identifying") String springProfilesActive, @RequestBody RecordBrandReqBean recordBrandReqBean) {

        List<UserBrandCombinedInfo> brandInfo = userBrandInfoService.getUserBrandInfo(Integer.parseInt(userId));

        //20200423
        if(recordBrandReqBean!=null && recordBrandReqBean.getBrandId()!=null) {
            if (brandInfo != null) {
                for(UserBrandCombinedInfo userBrandInfo :brandInfo){
                    if(userBrandInfo.getBrandId().equals(Integer.parseInt(recordBrandReqBean.getBrandId()))){
                        brandInfo.remove(userBrandInfo);
                        break;
                    }
                }

                if (brandInfo.size() > 4) {
                    brandInfo.remove(brandInfo.size()-1);
                }
                UserBrandCombinedInfo userBrandCombinedInfo = new UserBrandCombinedInfo();
                userBrandCombinedInfo.setBrandId(Integer.parseInt(recordBrandReqBean.getBrandId()));
//                brandInfo.add(0,userBrandCombinedInfo);
                brandInfo.add(userBrandCombinedInfo);
                String strUserBrand = "";
                for (int i=brandInfo.size()-1;i>=0;i--) {
                    strUserBrand = strUserBrand + "," + brandInfo.get(i).getBrandId();
                }
                userBrandInfoService.storeUserSubBrand(Integer.valueOf(userId), strUserBrand.substring(1));
                brandInfo = userBrandInfoService.getUserBrandInfo(Integer.parseInt(userId));
            }
        }
        /*文章*/
        List<ArticleTypeInfo> articleTypeInfo = Lists.newArrayList();

        StringBuffer articleTypeIdsSb = new StringBuffer();

        if (CollectionUtils.isEmpty(brandInfo)) {

            //查询该用户是否有自己的订阅文章类型
            UserRelateArticleTypeInfo userRelateArticleTypeInfo = userRelateArticleTypeInfoService.getUserRelateArticleTypeInfo(Integer.parseInt(userId));

            if (userRelateArticleTypeInfo != null && userRelateArticleTypeInfo.getId() != null) {

                String articleTypeIds = userRelateArticleTypeInfo.getArticleTypeIds();

                if (StringUtils.isNotBlank(articleTypeIds)) {
                    articleTypeIdsSb.append(articleTypeIds);
                }

            }

            //如果用户没有自己的订阅信息，则查询平台的订阅信息
            //屏蔽于20200219
//            if (StringUtils.isBlank(articleTypeIdsSb)) {
//
//                brandInfo.forEach(info -> {
//
//                    int brandId = info.getBrandId();
//
//                    //查询改品牌是否有关联的类型
//                    String articleTypeIds = articleBrandAndTypeInfoService.getBrandRelatedArticleTypeIds(brandId);
//                    if (StringUtils.isNotBlank(articleTypeIds)) {
//                        articleTypeIdsSb.append(articleTypeIds);
//                        articleTypeIdsSb.append(",");
//                    }
//
//                });
//
//            }

        }

        if (StringUtils.isBlank(articleTypeIdsSb)) {
            articleTypeIdsSb.append("0,1,4,5,9");  //20200218 添加"0:直播" 分类
        }

        if (StringUtils.isNotBlank(articleTypeIdsSb) && articleTypeIdsSb.length() > 0) {

            List<String> articleTypeIds = Arrays.asList(articleTypeIdsSb.toString().split(","));

            List<String> distinctArticleTypeIds = articleTypeIds.stream()
                    .distinct().collect(Collectors.toList());

            if (distinctArticleTypeIds.size() > 0) {

                articleTypeInfo = articleTypeInfoService.getArticleTypeInfoByIds(distinctArticleTypeIds);

            }

        }

        if (CollectionUtils.isEmpty(articleTypeInfo) || articleTypeInfo.size() == 0) {

            articleTypeInfo = articleTypeInfoService.getArticleTypeInfo();

        }

        List<Map<String, Object>> platformArticleTypeInfo = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(articleTypeInfo)) {
            articleTypeInfo.forEach(info -> {
                HashMap<String, Object> infoMap = Maps.newHashMapWithExpectedSize(2);
                infoMap.put("articleTypeId", info.getId());
                infoMap.put("articleTypeName", info.getArticleTypeName());

                platformArticleTypeInfo.add(infoMap);
            });
        }

        // 添加访问记录
        this.addAccessRecord(Integer.valueOf(userId),springProfilesActive);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(5);
        ArticleTypeInfo manualInfo = articleTypeInfoService.getArticleTypeInfoByArticleTypeName("常见问题");
        resultMap.put("manualInfo", manualInfo);
        resultMap.put("articleTypeInfo", platformArticleTypeInfo);
        resultMap.put("brandInfo", brandInfo);
        /*ljt 20201027 start*/
        //如果是金钻云公众号标识（prodjzyxt）,屏蔽品牌。
        resultMap.put("identifying", springProfilesActive);
        /*ljt 20201027 end*/

        //if (identifying.equals("prodjzyxt")) {
            List<Object> imgUrls = this.headlineService.selectHeadimgUrlsByGzhCode(springProfilesActive);
            resultMap.put("imgUrls", imgUrls);
        //}

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    /**
     * 异步添加用户访问记录
     * @param userId
     */
    @Async
    void addAccessRecord(Integer userId,String springProfilesActive){
        PageDetailLog log = new PageDetailLog();
        log.setAccessTime(new Date());
        log.setGzhCode(springProfilesActive);
        log.setPageName("文章库");
        log.setUserId(userId);
        this.connectionInfoService.addAccessRecord(log);
    }

    /**
     * @Author: yl
     * @Description: 文章视频选择分类：
     * @Date: 11:33 2020/7/21
     * @Param:
     * @param
     * @Return:
     **/
    @PostMapping(value = "/getPlatformArticleTypeInfo", produces = "application/json;charset=UTF-8")
    public RespData getUserArticleTypeInfo(@RequestHeader("userId") String userId) {

        List<ArticleTypeInfo> articleTypeInfoList = articleTypeInfoService.getArticleTypeInfo();

        //查询改用户是否有自己的订阅文章类型
        UserRelateArticleTypeInfo userRelateArticleTypeInfo = userRelateArticleTypeInfoService.getUserRelateArticleTypeInfo(Integer.parseInt(userId));

        List<String> articleTypeIdsList = Lists.newArrayList();
        if (userRelateArticleTypeInfo != null && userRelateArticleTypeInfo.getId() != null) {

            String articleTypeIds = userRelateArticleTypeInfo.getArticleTypeIds();

            if (StringUtils.isNotBlank(articleTypeIds)) {

                articleTypeIdsList = Arrays.asList(articleTypeIds.split(","));

            }

        }

        List<CombinedUserArticleTypeInfo> userArticleTypeInfos = Lists.newArrayList();

        for (ArticleTypeInfo articleTypeInfo : articleTypeInfoList) {

            CombinedUserArticleTypeInfo combinedUserArticleTypeInfo = new CombinedUserArticleTypeInfo();
            combinedUserArticleTypeInfo.setArticleTypeId(articleTypeInfo.getId());
            combinedUserArticleTypeInfo.setArticleTypeName(articleTypeInfo.getArticleTypeName());

            if (CollectionUtils.isNotEmpty(articleTypeIdsList) && articleTypeIdsList.size() > 0) {

                boolean matchResult = articleTypeIdsList.stream().parallel().anyMatch(info -> Integer.parseInt(info) == articleTypeInfo.getId());

                if (matchResult) {
                    combinedUserArticleTypeInfo.setEffectiveStatus(1);
                } else {
                    combinedUserArticleTypeInfo.setEffectiveStatus(0);
                }

            } else {
                combinedUserArticleTypeInfo.setEffectiveStatus(0);
            }

            userArticleTypeInfos.add(combinedUserArticleTypeInfo);
        }


        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        RespData respData = new RespData();

        resultMap.put("platformArticleTypeInfo", userArticleTypeInfos);

        respData.setData(resultMap);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/recordUserArticleTypeInfo", produces = "application/json;charset=UTF-8")
    public RespData recordUserArticleTypeInfo(@RequestHeader("userId") String userId, @RequestBody RecordUserArticleTypeInfoReqBean recordUserArticleTypeInfoReqBean) {

        if (recordUserArticleTypeInfoReqBean == null) {

            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;

        }

        String articleTypeIds = Optional.ofNullable(recordUserArticleTypeInfoReqBean.getArticleTypeIds()).orElse("");
        userRelateArticleTypeInfoService.recordUserRelateArticleTypeInfo(Integer.parseInt(userId), articleTypeIds);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }


    /**
     * 20200708 yl
     * 查询用户关注的素材分类以及品牌
     * 20200721 作废
     * @param userId
     * @return
     */
//    @PostMapping(value = "/selectUserAttentionMaterialTypeAndBrand", produces = "application/json;charset=UTF-8")
//    public RespData selectUserAttentionMaterialTypeAndBrand(@RequestHeader("userId") String userId ,@RequestBody RecordBrandReqBean recordBrandReqBean) {
//        Map<String,Object> map = Maps.newHashMapWithExpectedSize(2);
//        //获取用户关注的品牌
//        /*品牌*/
//        List<UserBrandCombinedInfo> brandInfo = userBrandInfoService.getUserBrandInfo(Integer.parseInt(userId));
//        //20200423
//        if(recordBrandReqBean!=null && recordBrandReqBean.getBrandId()!=null) {
//            if (brandInfo != null) {
//                for(UserBrandCombinedInfo userBrandInfo :brandInfo){
//                    if(userBrandInfo.getBrandId().equals(Integer.parseInt(recordBrandReqBean.getBrandId()))){
//                        brandInfo.remove(userBrandInfo);
//                        break;
//                    }
//                }
//
//                if (brandInfo.size() > 4) {
//                    brandInfo.remove(brandInfo.size()-1);
//                }
//                UserBrandCombinedInfo userBrandCombinedInfo = new UserBrandCombinedInfo();
//                userBrandCombinedInfo.setBrandId(Integer.parseInt(recordBrandReqBean.getBrandId()));
//                brandInfo.add(0,userBrandCombinedInfo);
//
//                String strUserBrand = "";
//                for (int i=brandInfo.size()-1;i>=0;i--) {
//                    strUserBrand = strUserBrand + "," + brandInfo.get(i).getBrandId();
//                }
//                userBrandInfoService.storeUserSubBrand(Integer.valueOf(userId), strUserBrand.substring(1));
//                brandInfo = userBrandInfoService.getUserBrandInfo(Integer.parseInt(userId));
//            }
//        }
//        map.put("brandInfo",brandInfo);
//        // 获取用户关注的分类
//        List<ArticleTypeInfo>  articleTypeInfos = this.articleTypeInfoService.selectUserAttentionMaterialType(Integer.parseInt(userId));
//        map.put("articleTypeInfo",articleTypeInfos);
//        RespData respData = new RespData();
//        respData.setCode(ReturnCode.NORMAL_SUCC);
//        respData.setData(map);
//        respData.setMsg("成功");
//        return respData;
//    }

    /**
     * 20200708 yl
     * 20200721 作废 查询用户基础类
     * @param userId
     * @return
     */
//    @PostMapping(value = "/selectUserAttentionMaterialType", produces = "application/json;charset=UTF-8")
//    public RespData selectUserAttentionMaterialType(@RequestHeader("userId") String userId ) {
//        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(1);
//        // 基础分类
//        List<ArticleTypeInfo> articleTypeInfo = this.articleTypeInfoService.getArticleTypeInfo();
//        // 用户关注的分类
//        List<ArticleTypeInfo>  articleTypeInfos = this.articleTypeInfoService.selectUserAttentionMaterialType(Integer.parseInt(userId));
//        resultMap.put("platformArticleTypeInfo", articleTypeInfo.stream().map(articleType -> {
//            CombinedUserArticleTypeInfo combinedUserArticleTypeInfo = new CombinedUserArticleTypeInfo();
//            combinedUserArticleTypeInfo.setArticleTypeId(articleType.getId());
//            combinedUserArticleTypeInfo.setArticleTypeName(articleType.getArticleTypeName());
//            combinedUserArticleTypeInfo.setEffectiveStatus(0);
//            if(CollectionUtils.isNotEmpty(articleTypeInfos)){
//                articleTypeInfos.forEach(articleT ->{
//                    if (articleType.getId().equals(articleT.getId())){
//                        combinedUserArticleTypeInfo.setEffectiveStatus(1);
//                    }
//                });
//            }
//            return combinedUserArticleTypeInfo;
//        }).collect(Collectors.toList()));
//        RespData respData = new RespData();
//        respData.setCode(ReturnCode.NORMAL_SUCC);
//        respData.setData(resultMap);
//        respData.setMsg("成功");
//        return respData;
//    }

    /**
     * @Author: chujiu
     * @Description: //素材关注信息
     * @Date: 16:45 2020/7/21
     * @Param:
     * @param:
     * @Return:
     */
    @PostMapping(value = "/selectUserAttentionMaterialType", produces = "application/json;charset=UTF-8")
    public RespData selectUserAttentionMaterialType(@RequestHeader("userId") String userId ) {
        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(1);
        // 基础分类
        List<ArticleTypeInfo> articleTypeInfo = this.articleTypeInfoService.getArticleTypeInfoItem();
        // 用户关注的分类
        List<ArticleTypeInfo>  articleTypeInfos = this.articleTypeInfoService.selectUserAttentionMaterialTypeItem(Integer.parseInt(userId));
        resultMap.put("platformArticleTypeInfo", articleTypeInfo.stream().map(articleType -> {
            CombinedUserArticleTypeInfo combinedUserArticleTypeInfo = new CombinedUserArticleTypeInfo();
            combinedUserArticleTypeInfo.setArticleTypeId(articleType.getId());
            combinedUserArticleTypeInfo.setArticleTypeName(articleType.getArticleTypeName());
            combinedUserArticleTypeInfo.setEffectiveStatus(0);
            if(CollectionUtils.isNotEmpty(articleTypeInfos)){
                articleTypeInfos.forEach(articleT ->{
                    if (articleType.getId().equals(articleT.getId())){
                        combinedUserArticleTypeInfo.setEffectiveStatus(1);
                    }
                });
            }
            return combinedUserArticleTypeInfo;
        }).collect(Collectors.toList()));
        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    /**
     * @Author: chujiu
     * @Description: //素材关注信息
     * @Date: 11:45 2020/7/21
     * @Param:
     * @param:
     * @Return:
     */
    @PostMapping(value = "/selectUserAttentionMaterialTypeAndBrand", produces = "application/json;charset=UTF-8")
    public RespData selectUserAttentionMaterialTypeAndBrand(@RequestHeader("userId") String userId ,@RequestHeader("identifying") String springProfilesActive,@RequestBody RecordBrandReqBean recordBrandReqBean) {
        Map<String,Object> resultMap = Maps.newHashMapWithExpectedSize(3);
        //获取用户关注的品牌
        /*品牌*/
        List<UserBrandCombinedInfo> brandInfo = userBrandInfoService.getUserBrandInfo(Integer.parseInt(userId));
        //20200423
        if(recordBrandReqBean!=null && recordBrandReqBean.getBrandId()!=null) {
            if (brandInfo != null) {
                for(UserBrandCombinedInfo userBrandInfo :brandInfo){
                    if(userBrandInfo.getBrandId().equals(Integer.parseInt(recordBrandReqBean.getBrandId()))){
                        brandInfo.remove(userBrandInfo);
                        break;
                    }
                }

                if (brandInfo.size() > 4) {
                    brandInfo.remove(brandInfo.size()-1);
                }
                UserBrandCombinedInfo userBrandCombinedInfo = new UserBrandCombinedInfo();
                userBrandCombinedInfo.setBrandId(Integer.parseInt(recordBrandReqBean.getBrandId()));
                brandInfo.add(0,userBrandCombinedInfo);

                String strUserBrand = "";
                for (int i=brandInfo.size()-1;i>=0;i--) {
                    strUserBrand = strUserBrand + "," + brandInfo.get(i).getBrandId();
                }
                userBrandInfoService.storeUserSubBrand(Integer.valueOf(userId), strUserBrand.substring(1));
                brandInfo = userBrandInfoService.getUserBrandInfo(Integer.parseInt(userId));
            }
        }
        resultMap.put("brandInfo",brandInfo);
        // 获取用户关注的分类

        List<ArticleTypeInfo> articleTypeInfos = new ArrayList<>();

        articleTypeInfos = this.articleTypeInfoService.selectUserAttentionMaterialTypeItem(Integer.parseInt(userId));

        //如果没有 关注分类，就默认关注 4个分类
        if(CollectionUtils.isEmpty(articleTypeInfos)){
            MateriaUserRelateTypeInfo materiaUserRelateTypeInfo=new MateriaUserRelateTypeInfo();
            materiaUserRelateTypeInfo.setUserId(Integer.valueOf(userId));
            materiaUserRelateTypeInfo.setGzhCode(springProfilesActive);
            materiaUserRelateTypeInfo.setCreateTime(new Date());

            List<String> articleTypeIdList =new ArrayList<>();
            articleTypeIdList.add("33");
            articleTypeIdList.add("30");
            articleTypeIdList.add("31");
            articleTypeIdList.add("32");

            this.articleTypeInfoService.addUserAttentionMaterialTypeAndBrand(materiaUserRelateTypeInfo,articleTypeIdList);

            articleTypeInfos = this.articleTypeInfoService.selectUserAttentionMaterialTypeItem(Integer.parseInt(userId));
        }

        List<Map<String, Object>> platformArticleTypeInfo = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(articleTypeInfos)) {
            articleTypeInfos.forEach(info -> {
                HashMap<String, Object> infoMap = Maps.newHashMapWithExpectedSize(2);
                infoMap.put("articleTypeId", info.getId());
                infoMap.put("articleTypeName", info.getArticleTypeName());

                platformArticleTypeInfo.add(infoMap);
            });
        }

        resultMap.put("articleTypeInfo",platformArticleTypeInfo);
        resultMap.put("countTest", "countTest");
        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }


    /**
     * 20200708 yl
     * 用户关注素材分类
     * @param userId
     * @param materiaUserRelateTypeInfo
     * @return
     */
    @PostMapping(value = "/addUserAttentionMaterialType", produces = "application/json;charset=UTF-8")
    public RespData addUserAttentionMaterialType(@RequestHeader("userId") String userId,@RequestHeader("identifying") String springProfilesActive,@RequestBody MateriaUserRelateTypeInfo materiaUserRelateTypeInfo) {
        RespData respData = new RespData();
        if (null == materiaUserRelateTypeInfo || StringUtils.isBlank(materiaUserRelateTypeInfo.getArticleTypeIds())){
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("请选择分类");
            return respData;
        }
        List<String> articleTypeIdList = Arrays.asList(materiaUserRelateTypeInfo.getArticleTypeIds().split(","));
        if (CollectionUtils.isEmpty(articleTypeIdList) || articleTypeIdList.size() > 5){
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("分类最多只能关注5个");
            return respData;
        }
        materiaUserRelateTypeInfo.setUserId(Integer.valueOf(userId));
        materiaUserRelateTypeInfo.setGzhCode(springProfilesActive);
        materiaUserRelateTypeInfo.setCreateTime(new Date());
        this.articleTypeInfoService.addUserAttentionMaterialTypeAndBrand(materiaUserRelateTypeInfo,articleTypeIdList);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/addOneMaterialId", produces = "application/json;charset=UTF-8")
    public RespData addOneMaterialId(@RequestHeader("userId") String userId,@RequestHeader("identifying") String springProfilesActive,@RequestBody MateriaUserRelateTypeInfo materiaUserRelateTypeInfo) {
        Map<String,Object> resultMap = Maps.newHashMapWithExpectedSize(1);
        String ids = materiaUserRelateTypeInfo.getArticleTypeIds();
        RespData respData = new RespData();
        if (null == materiaUserRelateTypeInfo || StringUtils.isBlank(ids)){
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("");
            return respData;
        }

        List<ArticleTypeInfo> articleTypeInfos = Lists.newArrayList();

        articleTypeInfos = this.articleTypeInfoService.selectUserAttentionMaterialTypeItem(Integer.valueOf(userId).intValue());

        if (!CollectionUtils.isEmpty(articleTypeInfos)) {
            List<String> articleTypeIdList =new ArrayList<>();

            int m = articleTypeInfos.size();
            for (int i = 0; i < m; i++) {
                ArticleTypeInfo articleTypeInfo = articleTypeInfos.get(i);
                if(!articleTypeInfo.getId().toString().equals(ids)){
                    articleTypeIdList.add(articleTypeInfo.getId().toString());
                }
            }

            articleTypeIdList.add(0, ids);

            if (articleTypeIdList.size() > 4) {
                articleTypeIdList.remove(articleTypeIdList.size() - 1);
            }

            materiaUserRelateTypeInfo.setUserId(Integer.valueOf(userId));
            materiaUserRelateTypeInfo.setGzhCode(springProfilesActive);
            materiaUserRelateTypeInfo.setCreateTime(new Date());
            this.articleTypeInfoService.addUserAttentionMaterialTypeAndBrand(materiaUserRelateTypeInfo,articleTypeIdList);

            this.articleTypeInfoService.selectUserAttentionMaterialTypeItem(Integer.parseInt(userId));

            articleTypeInfos = this.articleTypeInfoService.selectUserAttentionMaterialTypeItem(Integer.valueOf(userId).intValue());
        }

        resultMap.put("articleTypeInfo",articleTypeInfos);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

}
